<?php

namespace app\admin\controller;

use app\admin\service\ReasonService;

class ReasonController extends CommonController
{
    // 获取理由数据的分页列表
    public function getReasonList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getList();
        return $this->return_result($this->returnData);
    }

    // 获取对应类型的理由数据的列表
    public function getReasonListByType(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getListByType();
        return $this->return_result($this->returnData);
    }

    // 添加理由
    public function toAddReason(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toAdd();
        return $this->return_result($this->returnData);
    }

    // 更新理由
    public function toUpdateReason(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdate();
        return $this->return_result($this->returnData);
    }

    // 理由的详细内容
    public function getReasonDetail(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getDetail();
        return $this->return_result($this->returnData);
    }

    // 更新文章类型状态
    public function toUpdateStatusReason(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdateStatus();
        return $this->return_result($this->returnData);
    }

    // 删除理由
    public function toDelReason(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(ReasonService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toDel();
        return $this->return_result($this->returnData);
    }

}